!lm12
!rm75
Benchmarking Block MOVES..................William R. Savoie

While working on my new soon-to-be-released data file system, I came to see the importance of a speedy 6502 block move routine.  I have resisted "moves" like the coming of winter.  I have a super two pass sort routine that is very fast.  Providing a person has less than 2000 files there is no need to do much file moving, since only pointers need move.  (My system has a 64K card, giving me a 112K system.)

Unfortunately, the real world needs some 10,000 or more files, and these of course must be sorted too.  By physically moving the files as directed by the sorted pointers, and then moving all this to disk, it is possible to use a merge sort to get the whole job done in the least amount of time.  With this preamble behind us, let's get on the move!

I have benchmarked three approaches to moving blocks:  the monitor move down (located at $FE2C) which I'm sure you all have used, and its variation, a similar move up routine.  Next is the Applesoft block move, and third is a self modifying move which I call "Quick Move".

To ease such a tedious undertaking, I have included a BASIC connection to pass variables and determine the benchmark precision.  To help further, I have added a hex converter, a memory dump routine, and an automatic 3D0G vector using the ctrl-Y command from the monitor.  To help with the problem of what block of memory was moved where, I wrote a memory fill routine.  This acts to place the memory address back into memory, on two-byte boundaries.  You can easily read memory to see where it came from.

My first benchmark was a block move of 10,000 bytes made 100 times.  The next was a move of 10,240 bytes, again made 100 times.  Here are the conditions and resulting times:

                          mon up  mon dn     AS       QM
Case I    Lo=18674=$48F0    47      53      17.2     15.3   seconds
Case II   Lo=18432=$4800    48.7    54.7    16.7     14.7

Note:  0.5 seconds of these values due to BASIC overhead.

As you can see, the old monitor move is not made for high speed moves.  For one thing, a two-byte subtraction is carried out for each byte that is moved.  It is much more efficient to do the subtraction only once, before you start.  A closer look shows that it is faster to move more data, providing you move a whole number of memory pages!  The time needed to move the "extra" 240 bytes was negative 0.5 seconds for the Applesoft block move and negative 0.6 seconds for the "Quick Move".  There was no sensitivity to start and destination boundaries.  "Quick Move" was 3.7 times faster than the monitor move!

I tried putting the first half of Quick Move on page zero at $A0, but the speed improvement was only 0.7 seconds (about 5%) over the time it took when located at $3000.

As a further note, each move routine requires its own parameter organization.  If files are to be moved and not lost, attention must be paid to exact specification of end points and lengths.
